package com.example.com.skills_utf8;

import com.utils.NetHelper;
import com.utils.Utils1;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ProgressBar1Activity extends Activity{

	
	ProgressBar1Activity activity = this;
	ProgressDialog dialog_bt_start3;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_progress_bar1);
		
		
		Button bt_start =(Button)findViewById(R.id.bt_start);
		bt_start.setOnClickListener( new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				new com.utils.TIME(){

					@Override
					public void fuc() {
						// TODO Auto-generated method stub
						
						Looper.prepare();   //如果这样使用,
						
						ProgressDialog dialog = new ProgressDialog(activity);
						dialog.setMax(100);
						dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
						dialog.setCancelable(false);
						dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确认", 
								new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								
								dialog.dismiss();
								
							}
						});
						dialog.show();
						
						
						
						// do hardwork 并更新进度. 将导致阻塞住该进度框的显示,甚至做完之后才显示
						
						
						Looper.loop();
						
					}
					
				}.get_elapsed_time_Thead();

				
			
				
				
				
				
				
			}
		});
		
	
		
		
		Button bt_start2 =(Button)findViewById(R.id.bt_start2);
		bt_start2.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				final ProgressDialog dialog = new ProgressDialog(activity);
				dialog.setMax(100);
				dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			//	dialog.setCancelable(false);
				dialog.show();
				
				
			
				new Thread(){
					
					public void run() {
						
						for(int i =1; i<=10; i++){
							Utils1.do_hardwork();
							dialog.setProgress(i*10);
						}
						
					};
					
					
				}.start();
				
				
				
				
				
				
			}
		});
		
		
		
		Button bt_start3 = (Button)findViewById(R.id.bt_start3);
		bt_start3.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				
	
				
			new Thread(){
				
				
				public void run() {
					
					
					new Thread(){
						
						@Override
						public void run() {
							// TODO Auto-generated method stub
							
							Looper.prepare();	
							
							dialog_bt_start3 = new ProgressDialog(activity);
							dialog_bt_start3.setMax(100);
							dialog_bt_start3.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
							dialog_bt_start3.show();
							
							Looper.loop();
						}
					}.start();
					
					
					
					
					for(int i =1; i<=10; i++){
						
						if(dialog_bt_start3!=null)
						dialog_bt_start3.setProgress(i*10); 
						Utils1.do_hardwork();
						
					}
					
					dialog_bt_start3.dismiss();
				
				};
				
			}.start();	
				
				
				
			}
		});
		
		
		
		
		
	}
	
	
	
	
	
	
	
}
